import Layout from '@/views/Layout/index.vue'
import Login from '@/views/Login/index.vue'
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
import subCategory from '@/views/subCategory/index.vue'
import Detail from '@/views/Detail/index.vue'
import CartList from '@/views/CartList/index.vue'
import { createRouter, createWebHistory } from 'vue-router'

import ImageView from "@/components/ImageView/index.vue"
import CheckOut from "@/views/CheckOut/index.vue"
import Pay from "@/views/Pay/index.vue"
import PayBack from "@/views/Pay/PayBack.vue"
//创建router实例 创建history模式路由
const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    // path 和 component 对应关系的 位置
    routes: [
        {
            path: '/',
            component: Layout,
            children: [
                {
                    path: '',
                    component: Home,
                },
                {
                    path: `category/:id`,
                    component: Category,
                },
                {
                    path: `category/sub/:id`,
                    component: subCategory,
                },
                {
                    path: `detail/:id`,
                    component: Detail,
                },
            ]
        },
        {
            path: '/login',
            component: Login
        },
        {
            path: '/test',
            component: ImageView
        },
        {
            path: '/cartlist',
            component: CartList
        },
        {
            path: '/checkout',
            component: CheckOut
        },
        {
            path: '/pay',
            component: Pay
        },
        {
            path: '/paycallback', // 注意路径，必须是paycallback
            component: PayBack
        }

    ],
    //路由滚动行为定制
    scrollBehavior() {
        return {
            top: 0
        }
    }
})

export default router
